/*eslint-disable */
@Inject('$log', '$scope', '$http', '$state', 'documentService', 'ngDialogService', 'ngDialog')
class DocumentMgtController {
  constructor() {
    // 初始化页面
    this.initDocumentMgtView($state.params.type);
  }

  loadImage(image) {
    return require(`../../assets/images/document/${image.name}.png`);
  };

  toDocumentItemMgt(innerItem) {
    this.$state.go('documentItemMgt', {
      boxId: innerItem.id,
      name: innerItem.name,
      documentType: this.$state.params.type,
      role: innerItem.role,
    });
  }

  getDocumentList4show() {
    let step = 0;
    let index = 0;
    let result = [];
    this.documentList.forEach((item) => {
      if (step%5 == 0) {
      result.push([]);
    }
    index = result.length;
    step++;
    result[index-1].push(item);
  });
    return result;
  };

  initDocumentMgtView(type) {
    this.documentService
      .queryBox(type)
      .then((res) => {
        if (res.success) {
          // 考核项数据加入$scope
          this.documentList = res.rows;;
          // 将原始数据变化为行展示内容
          this.documentList4show = this.getDocumentList4show();
        }
      });
  }

}

export default DocumentMgtController;
